<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\SOrderInfo;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class OrderController extends Controller {
	use HasResourceActions;

	/**
	 * Index interface.
	 *
	 * @param Content $content
	 * @return Content
	 */
	public function index(Content $content) {
		return $content
			->header('Index')
			->description('description')
			->body($this->grid());
	}

	/**
	 * Show interface.
	 *
	 * @param mixed $id
	 * @param Content $content
	 * @return Content
	 */
	public function show($id, Content $content) {
		return $content
			->header('Detail')
			->description('description')
			->body($this->detail($id));
	}

	/**
	 * Edit interface.
	 *
	 * @param mixed $id
	 * @param Content $content
	 * @return Content
	 */
	public function edit($id, Content $content) {
		return $content
			->header('Edit')
			->description('description')
			->body($this->form()->edit($id));
	}

	/**
	 * Create interface.
	 *
	 * @param Content $content
	 * @return Content
	 */
	public function create(Content $content) {
		return $content
			->header('Create')
			->description('description')
			->body($this->form());
	}

	/**
	 * Make a grid builder.
	 *
	 * @return Grid
	 */
	protected function grid() {
		$grid = new Grid(new SOrderInfo);

		$grid->id('Id')->sortable();
		$grid->user_id('User id');
		$grid->info_id('Info id');
		$grid->info_type('Info type');
		$grid->get_type('Get type');
		$grid->pay_price('Pay price');
		$grid->pay_type('Pay type');
		$grid->actual_price('Actual price');
		$grid->voucher_id('Voucher id');
		$grid->lesson_type_id('Lesson type id');
		$grid->lesson_num('Lesson num');
		$grid->pay_time('Pay time');
		$grid->created_at('Created at');
		$grid->updated_at('Updated at');
		$grid->deleted_at('Deleted at');

		return $grid;
	}

	/**
	 * Make a show builder.
	 *
	 * @param mixed $id
	 * @return Show
	 */
	protected function detail($id) {
		$show = new Show(SOrderInfo::findOrFail($id));

		$show->id('Id');
		$show->user_id('User id');
		$show->info_id('Info id');
		$show->info_type('Info type');
		$show->get_type('Get type');
		$show->pay_price('Pay price');
		$show->pay_type('Pay type');
		$show->actual_price('Actual price');
		$show->voucher_id('Voucher id');
		$show->lesson_type_id('Lesson type id');
		$show->lesson_num('Lesson num');
		$show->pay_time('Pay time');
		$show->created_at('Created at');
		$show->updated_at('Updated at');
		$show->deleted_at('Deleted at');

		return $show;
	}

	/**
	 * Make a form builder.
	 *
	 * @return Form
	 */
	protected function form() {
		$form = new Form(new SOrderInfo);

		$form->number('user_id', 'User id');
		$form->number('info_id', 'Info id');
		$form->number('info_type', 'Info type');
		$form->number('get_type', 'Get type');
		$form->number('pay_price', 'Pay price');
		$form->number('pay_type', 'Pay type');
		$form->number('actual_price', 'Actual price');
		$form->number('voucher_id', 'Voucher id');
		$form->number('lesson_type_id', 'Lesson type id');
		$form->number('lesson_num', 'Lesson num');
		$form->datetime('pay_time', 'Pay time')->default(date('Y-m-d H:i:s'));

		return $form;
	}
}
